package com.sgb.kjwl.viewmodel.business;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.business.MemberInfoEntity;
import com.sgb.kjwl.repository.SelfRepertory;
import com.sgb.kjwl.view.ui.fragment.business.MemberInfoFragment;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MemberInfoFragModel extends BaseViewModel {

    private final MemberInfoFragment fragment;

    public MemberInfoFragModel(MemberInfoFragment fragment, SelfRepertory selfRepertory) {
        this.fragment = fragment;
    }

    public void getMemberInfo(String id) {
            APIManager.getInstance().getBusinessManagementAPI().getMemberCompanyInfo(id).enqueue(new Callback<BaseEntity<MemberInfoEntity>>() {
                @Override
                public void onResponse(Call<BaseEntity<MemberInfoEntity>> call, Response<BaseEntity<MemberInfoEntity>> response) {
                    if (response.body() == null || response.body().getData() == null){
                        return;
                    }

                    fragment.showData(response.body().getData());
                }

                @Override
                public void onFailure(Call<BaseEntity<MemberInfoEntity>> call, Throwable t) {

                }
            });
        }
}
